<?php

namespace App\Admin\Controllers\Api\V1;

use App\Models\DepositSetup;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;

class DepositSetupController extends Controller
{
    use HasResourceActions;

    /**
     * Index interface.
     *
     * @param Content $content
     * @return Content
     */
    public function index(Content $content)
    {
        return $content
            ->header('入金')
            ->description('管理')
            ->body($this->grid());
    }

    /**
     * Show interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function show($id, Content $content)
    {
        return $content
            ->header('入金')
            ->description('详情')
            ->body($this->detail($id));
    }

    /**
     * Edit interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function edit($id, Content $content)
    {
        return $content
            ->header('入金')
            ->description('编辑')
            ->body($this->form()->edit($id));
    }

    /**
     * Create interface.
     *
     * @param Content $content
     * @return Content
     */
    public function create(Content $content)
    {
        return $content
            ->header('入金')
            ->description('创建')
            ->body($this->form());
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new DepositSetup);

        date_default_timezone_set('PRC');
        $grid->model()->orderBy('created_at', 'desc');

        $grid->id('编号');
        $grid->min_amount('最小入金金额');
        $grid->max_amount('最大入金金额');

        $grid->created_at('创建时间')->display(function ($created_at) {
            return date('Y-m-d H:i:s',$created_at);
        });
        $grid->updated_at('编辑时间')->display(function ($created_at) {
            return date('Y-m-d H:i:s',$created_at);
        });

        return $grid;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new DepositSetup);

        $form->decimal('min_amount', '最小入金金额')->rules('required');
        $form->decimal('max_amount', '最大入金金额')->rules('required');;

        return $form;
    }
}
